#include <stdio.h>
#include <stdlib.h>
typedef unsigned packed_t;
	
int xbyte(packed_t word, int bytenum)
{
	return (word >> 8 * bytenum) & 0xFF;
}

int main()
{
	//unsigned int x = 0xAABBCCDD;
    unsigned int x = 0xFF;
  	int n;
	
	printf("\nThis program extracts each byte from a word (32-bit). \n");
	printf("Note: Each Hex value is 4bits. 2 Hex values is 1byte\n\n");
	 printf("\n32-bit Word is %X\n",x);

	    for (n=0; n<=3; n++) {
	        printf("byte %d of 0x%X is 0x%X\n",n,x,xbyte(x,n));
	    }

	printf("\nThe Hex Value: %X",(x ));
	printf("\n%X",(x & 0xFF));
	printf("\n%X",(x >> 8 * 0) & 0xFF);
	printf("\n%X",(x >> 8 * 1) & 0xFF);
	printf("\n%X",(x >> 8 * 2) & 0xFF);
	printf("\n%X\n",(x >> 8 * 3) & 0xFF);
	
	return 0;
}

